package com.libbase.utils

import android.os.Handler
import android.os.Looper
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors

class ThreadUtils private constructor() {
    companion object {
        val instance: ThreadUtils by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            ThreadUtils()
        }
    }

    private val executorService: ExecutorService = Executors.newCachedThreadPool()

    fun execute(command: Runnable) {
        executorService.execute(command)
    }

    fun executeInMainThread(command: Runnable) {
        Handler(Looper.getMainLooper()).post(command)
    }
}